package com.situ.day4;

import java.util.Scanner;

import org.junit.Test;

public class OOPDemo {
	@Test
	public void test1() {
		int num = 3;
		int[] array = new int[3];
		Student zhansan = new Student();
		//给对象属性赋值
		zhansan.id = 001;
		zhansan.age = 20;
		zhansan.name = "zhangsan";
		zhansan.className = "Java1812";
		//调用对象的方法
		zhansan.study();
		Student lisi = new Student();
		lisi.id = 002;
		lisi.age = 34;
		lisi.name = "lisi";
		lisi.className = "UI";
		lisi.study();
	}
	
	@Test
	public void test2() {
		Teacher teacher = new Teacher();
		teacher.id = 001;
		teacher.age = 33;
		teacher.name = "wangwu";
		teacher.teach();
	}
	
	// 输入一组学生信息 Student[] students = new Student[4];
	@Test
	public void test3() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量");
		int count = scanner.nextInt();
		Student[] students = new Student[count];
		for (int i = 0; i < students.length; i++) {
			Student student = new Student();
			System.out.println("请输入学生的编号");
			student.id = scanner.nextInt();
			System.out.println("请输入学生的名字");
			student.name = scanner.next();
			System.out.println("请输入年龄");
			student.age = scanner.nextInt();
			System.out.println("请输入班级");
			student.className = scanner.next();
			
			students[i] = student;
		}
		//通过for循环打印Student[]里面学生的信息
		for (int i = 0; i < students.length; i++) {
			System.out.println("------------");
			Student student = students[i];
			System.out.println(student.id);
			System.out.println(student.name);
			System.out.println(student.age);
			System.out.println(student.className);
		}
		
		while (true) {
			System.out.println("------------------------------");
			System.out.println("根据条件查询学生信息");
			System.out.println("根据id查找：1");
			System.out.println("根据名字查找：2");
			System.out.println("根据年龄查找：3");
			System.out.println("根据班级查找：4");
			System.out.println("退出程序：0");
			System.out.println("------------------------------");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("程序退出");
				break;
			}
			
			switch (type) {
			case 1://根据id查找
				System.out.println("请输入要查找的学生id：");
				int id = scanner.nextInt();
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (id == student.id) {//找到匹配的学生，打印相应信息
						System.out.println("-----------");
						System.out.println(student.id);
						System.out.println(student.name);
						System.out.println(student.age);
						System.out.println(student.className);
					}
				}
				break;
			case 2://根据名字查找
				System.out.println("请输入要查找的学生名字：");
				String name = scanner.next();
				for (int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (name.equals(student.name)) {//找到匹配的学生，打印相应信息
						System.out.println("-----------");
						System.out.println(student.id);
						System.out.println(student.name);
						System.out.println(student.age);
						System.out.println(student.className);
					}
				}
				break;
			default:
				break;
			}
		}
	}
}
